/*
 * Operator.java
 *
 * Copyright (c) Tomas Znamenacek
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

package net.sf.vofce.guts;

import java.util.Stack;

/**
 * Operator interface.
 * Common methods that operators have, so that we have some nice abstraction
 * level to work on. Numbers are operators, constants are operators, functions
 * (such as <code>cos(x)</code>) are operators.
 * 
 * @author Tomas Znamenacek
 */
public interface Operator extends Token {

	/**
	 * Returns operator arity.
	 * We only use zero arity (numbers, constants), arity 1 (sin, unary
	 * minus etc.) and arity 2 (binary minus, plus, multiplication etc.).
	 */
	public int getArity();
	
	/**
	 * Returns operator priority.
	 * The higher number, the higher priority.
	 */
	public int getPriority();

	/**
	 * Computes the value of the subtree this node is root of.
	 */
	public double evaluateSubTree();

	/**
	 * Renders the operator and its parameters in human syntax.
	 */
	public String toString(int parentPriority);
	
	/**
	 * Renders the operator and its parameters in TeX syntax.
	 */
	public String toTeX(int parentPriority);
	
	/**
	 * Renders the operator and its parameters in MathML syntax.
	 */
	public String toXML(int parentPriority);

	//
	// Node management
	//
	
	/** Set the left child of this node. */
	public void setLeftChild(Operator child);

	/** Set the right child of this node. */
	public void setRightChild(Operator child);

	/** Returns left node child. */
	public Operator getLeftChild();

	/** Returns right node child. */
	public Operator getRightChild();

	/**
	 * Returns <code>true</code> when the node is leaf.
	 * Leaf node is the node that has no children.
	 */
	public boolean isLeaf();

	/** Returns new operator instance. */
	public Operator getFreshInstance();
}
